package com.zbkj.service.assistant.model.vo;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.JSONUtil;
import com.zbkj.common.constants.AssistantConstants;
import com.zbkj.common.model.assistant.AssistantMessage;
import com.zbkj.service.assistant.model.dto.AssistantMessageContentDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class AssistantMessageVO extends AssistantMessage {

    @ApiModelProperty(value = "消息类型为关联系统业务单时的关联信息对象，4-商品 5-订单 6-售后单")
    public AssistantMessageContentDTO getContentObj() {
        if (ObjUtil.isNotEmpty(getContent()) && ObjUtil.isNotEmpty(getContentType()) && (getContentType() == 4 || getContentType() == 5 || getContentType() == 6)) {
            return JSONUtil.toBean(getContent(), AssistantMessageContentDTO.class);
        }
        return null;
    }

    /**
     * 获取经过处理的消息内容，用于展示到列表
     * @return
     */
    @ApiModelProperty(value = "可在列表中显示的消息内容")
    public String getViewTextContent() {
        String lastContent = this.getContent();
        if (AssistantConstants.Message.CONTENT_TYPE_TEXT.equals(this.getContentType())) {
            if (ObjUtil.isNotEmpty(lastContent) && lastContent.length() > 20) {
                lastContent = lastContent.substring(0, 15) + "...";
            }
        } else if (AssistantConstants.Message.CONTENT_TYPE_IMAGE.equals(this.getContentType())) {
            lastContent = "[图片]";
        } else if (AssistantConstants.Message.CONTENT_TYPE_VIDEO.equals(this.getContentType())) {
            lastContent = "[视频]";
        } else if (AssistantConstants.Message.CONTENT_TYPE_PRODUCT.equals(this.getContentType())) {
            lastContent = "[商品]";
        } else if (AssistantConstants.Message.CONTENT_TYPE_ORDER.equals(this.getContentType())) {
            lastContent = "[订单]";
        } else if (AssistantConstants.Message.CONTENT_TYPE_REFUND_ORDER.equals(this.getContentType())) {
            lastContent = "[售后单]";
        }
        return lastContent;
    }
}
